package com.zj.HJ;

import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;
import java.util.stream.Collectors;

public class 递增子序列 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());
        String input = sc.nextLine();
        System.out.println(getRes(input.split(" ")));
    }

    //186 186 150 200 160 130 197 200
    public static int getRes(String[] arr) {
        int len = 0;
        Integer[] nums = Arrays.asList(arr).stream().map(Integer::parseInt).collect(Collectors.toList()).toArray(new Integer[0]);
        int[] dp1 = getLongIncrease(nums);
        for (int i = 0; i < nums.length / 2; i++) {
            Integer temp = nums[i];
            nums[i] = nums[nums.length - 1 - i];
            nums[nums.length - 1 - i] = temp;
        }
        int[] dp2 = getLongIncrease(nums);
        for (int i = 0; i < nums.length; i++) {
            len = Math.max(len, dp1[i] + dp2[nums.length - 1 - i] - 1);
        }
        return nums.length - len;
    }

    public static int[] getLongIncrease(Integer[] arr) {
        int[] dp = new int[arr.length];
        Arrays.fill(dp, 1);
        int maxlen = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < i; j++) {
                if (arr[i] > arr[j] && dp[i] < dp[j] + 1) {
                    dp[i] = dp[j] + 1;
                }
            }
            maxlen = Math.max(maxlen, dp[i]);
        }
        return dp;
    }


}
